require(["common", "jQuery", "coAjax", "queryString", "hash_routie"], function(jSouper, $, coAjax, QueryString, hash_routie) {
	function _format_coupon_list(coupon_list) {
		App.set("$Cache.bus.coupon", coupon_list);
	};

	function _load_coupon_list() {
		coAjax.get(appConfig.bus.coupon_list, function(result) {
			_format_coupon_list(result.result);
		});
	};
	hash_routie.on("coupon", function() {
		_load_coupon_list();
	});
	App.set("$Event.bus.coupon.add", function() {
		var new_coupon_info = App.get("$Cache.bus.new_coupon");
		coAjax.post(appConfig.bus.coupon_add, new_coupon_info, function(result) {
			_format_coupon_list(result.result);
			alert("success","生成成功")
		});
	});
	App.set("$Event.bus.coupon.copy_code",function () {
		alert("success","优惠码已经复制到剪切板");
	});
	App.set("$Event.bus.coupon.remove", function(e, vm) {
		coAjax["delete"](appConfig.bus.coupon_remove + vm.get("_id"), function(result) {
			_format_coupon_list(result.result);
			alert("success","删除成功")
		});
	});
});